package com.sino.operation.util;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.junit.Test;

import java.lang.reflect.Field;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName EscBodyMapTestUtil
 * @Description TOD
 * @Author 北陈
 * @Date 2021/11/6 23:05
 * @Version 1.0
 */
public class EscBodyMapTestUtil<T> {

    @Test
    public void setTest() throws Exception {
//        User user = new User();
//        Class<? extends User> user2Class = user.getClass();
//        Field[] declaredFields = user2Class.getDeclaredFields();
//        for (Field field : declaredFields){
//            JsonProperty annotation = field.getAnnotation(JsonProperty.class);
//            String value = annotation.value();
//            String fildeName = field.getName();
//            System.out.println("字段名称："+value);
//            PropertyDescriptor pd = new PropertyDescriptor(field.getName(), user2Class);
//            byte[] items = fildeName.getBytes();
//            items[0] = (byte) ((char) items[0] - 'a' + 'A');
//            String s = new String(items);
//            System.out.println(s);
//            byte[] bytes = "id_aa_d".getBytes();
//            bytes[0]=(byte)((char)bytes[0]-'a'-'A');
//            String s1 = new String(bytes);
//            System.out.println(s1);
//            Method writeMethod = pd.getWriteMethod();
//            writeMethod.invoke(user,"333");
//            Type genericType = field.getGenericType();
//            Class<?> type = field.getType();
//            System.out.println(type.isAssignableFrom(List.class));
//
//        }
//        System.out.println(user);
    }

    public static <T> Map getMap(Class<T> clzz){
        Field[] declaredFields = clzz.getDeclaredFields();
        Map<String, Object> map = new HashMap<>();
        for (Field field:declaredFields){
            JsonProperty annotation = field.getAnnotation(JsonProperty.class);
            String value = annotation.value();
            String name = field.getType().getName();
            map.put(value,null);
//            if (name.contains("String")||name.contains("BigDecimal")||name.contains("Long")){
//                //String filedName=trans(value);
//
//            }
        }

        return map;
    }


    public static String trans(String name){
        char[] chars = name.toCharArray();
        int length = chars.length;
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int charValue=(int)chars[i];
            char aChar = chars[i];
            if (aChar!='_'){
                if (charValue >= 97 && charValue <= 122){
                    charValue = charValue - 32;
                    char value=(char) (charValue);
                    builder.append(value);
                }
            }else {
                builder.append(aChar);
            }
        }
        return builder.toString();
    }
}
